<template>
    <div class="base_index" ref="baseRef">
        <div class="item">
            <div class="label">环境名称</div>
            <div class="value">
                <el-input v-model="state.formData.base.name" style="width: 90%" placeholder="环境名称" />
            </div>
        </div>
        <div class="item" v-if="state.routeData.id == ''">
            <div class="label">新建环境数</div>
            <div class="value">
                <el-input-number v-model="state.formData.base.num" :min="1" controls-position="right"
                    style="width: 88px" />
            </div>
        </div>
        <div class="item">
            <div class="label">浏览器</div>
            <div class="value">
                <div class="flex">
                    <app-select-button :buttonType="'ChroBrowser'" :data="state.formData.base.browser"
                        :formData="state.formData" :optios="state.map.Chrome" @click="store.getUserAgent()" />
                    <app-select-button :buttonType="'FireBrowser'" :data="state.formData.base.browser"
                        :formData="state.formData" :optios="state.map.Firefox" style="margin-left: 8px;" @click="store.getUserAgent()" />
                </div>
                <div class="text" v-if="state.formData.base.browser.version == '-1'">基于 User Agent 匹配 {{
                    state.formData.base.browser.type }} 内核版本</div>
            </div>
        </div>
        <div class="item">
            <div class="label">操作系统</div>
            <div class="value" style="display: flex;">
                <template v-for="item in state.map.operate" :key="item.value">
                    <app-button2 style="margin-right: 8px;"
                        v-if="!(state.formData.base.browser.type == 'FireBrowser' && (item.value == 'Android' || item.value == 'iOS' || item.value == 'macOS'))"
                        :class="state.formData.base.operate == item.value ? 'app-button2-active' : ''"
                        @click="store.getPhone(item.value)">
                        <div class="between">
                            <img :src="state.formData.base.operate == item.value ? item.icon_active : item.icon">
                            <div>{{ item.value }}</div>
                        </div>
                    </app-button2>
                </template>

            </div>
        </div>
        <div class="item" v-if="state.formData.base.operate == 'Android' || state.formData.base.operate == 'iOS'">
            <div class="label">机型</div>
            <div class="value" style="display: flex;">
                <el-select v-model="state.formData.base.model" placeholder="选择机型" style="width: 90%">
                    <el-option v-for="item in state.map.modelOptions" :key="item.value" :label="item.label"
                        :value="item.value" />
                </el-select>
            </div>
        </div>
        <div class="item">
            <div class="label">User Agent</div>
            <div class="value">
                <div class="flex" v-if="state.routeData.id == ''">
                    <app-button3 v-model="state.formData.base.userAgent.type" :options="state.map.userAgentType" />
                </div>
                <div style="margin-top: 8px;width: 90%" class="flex">
                    <el-select v-model="state.formData.base.userAgent.inherit" multiple collapse-tags placeholder="选择类型"
                        style="width: 160px" @change="store.changeInherit">
                        <el-option label="全部" value="all" />
                        <el-option v-for="item in state.map.inheritOptions" :key="item.value" :label="item.label"
                            :value="item.value" />
                    </el-select>
                    <div style="padding-left: 8px;width: calc( 100% - 160px );">
                        <el-input class="user_agent_input" v-model="state.formData.base.userAgent.user_agent"
                            style="width: 100%" placeholder="环境名称">
                            <template #append>
                                <img @click="store.getUserAgent()" src="@/assets/home/random.png" style="width: 18px;height: 18px;cursor: pointer;"
                                    alt="">
                            </template>
                        </el-input>
                    </div>
                </div>
            </div>
        </div>
        <div class="item">
            <div class="label">分组</div>
            <div class="value" style="display: flex;">
                <el-select v-model="state.formData.base.group_id" placeholder="选择分组" style="width: 90%">
                    <el-option v-for="item in state.map.groupList" :key="item.value" :label="item.label"
                        :value="item.value" />
                </el-select>
            </div>
        </div>
    </div>
</template>

<script setup>
const { store, state } = inject('storejs')



const baseRef = ref(null)

onMounted(() => {
})
</script>

<style lang="scss" scoped>
.base_index {
    width: 100%;
    padding: 8px 16px 0 16px;
}

.item {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;

    .label {
        height: 30px;
        padding-bottom: 8px;
        color: #4e5969;
        font-size: 14px;
    }

    .value {
        .text {
            margin-top: 8px;
            color: #00000073;
            font-size: 14px;
        }

    }

}

.between {
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    img {
        width: 18px;
        height: 18px;
        margin-right: 8px;
    }
}

.flex {
    display: flex;
}

.column {
    display: flex;
    flex-direction: column;
}
</style>

<style>

.user_agent_input .el-input-group__append {
    background-color: #fff;
}
</style>